package com.niit.serializtion;


import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class person implements Writable {

    private  int id;
    private  String name;
    private  int age;
    private  String phone;


    //空构造器，  构造函数：当被实例化的时候就会调用方法
    public person(){

    }



    //有参构造函数
    public person(int id, String name, int age, String phone) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.phone = phone;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }


    @Override
    public String toString() {
        return "person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", phone='" + phone + '\'' +
                '}';
    }

    //序列化方法
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(id);
        out.writeUTF(name);
        out.writeInt(age);
        out.writeUTF(phone);

    }

    //反序列化方法,顺序一样；
    @Override
    public void readFields(DataInput in) throws IOException {
        this.id =in.readInt();
        this.name =in.readUTF();
        this.age =in.readInt();
        this.phone =in.readUTF();

    }


}
